package com.probiz.estore.exports.web.action;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;

import com.probiz.estore.core.controller.GenericStoreAdminController;
import com.probiz.estore.exports.model.Column;
import com.probiz.estore.exports.service.BaseExportManager;

public class BaseExportController extends GenericStoreAdminController<Object>  {
	protected BaseExportManager exportManager;
	
	public void setExportManager(BaseExportManager exportManager) {
		this.exportManager = exportManager;
	}


	public ModelAndView defaultAction(HttpServletRequest request, HttpServletResponse response){
		List<Column> columns = exportManager.getColumns(null);
		ModelAndView mv = new ModelAndView("exports/export");
		mv.addObject("columns", columns);
		return mv;
	}
	
	@Override
	protected void buildExcel(HttpServletRequest request,HttpServletResponse response,HSSFWorkbook workbook){
		//设置导出文件的名称
		response.setHeader("Content-Disposition", "attachment; filename="+getExportName());
		
		String[] ids = request.getParameterValues("multiIds");
		List<Object> list = this.exportManager.getDataSource(ids);
		this.exportManager.buildExcel(list, workbook);
	}

	protected String getExportName(){
		return null;
	}
	
	
	@Override
	protected String getEntityName(Object entity) {
		return null;
	}



	@Override
	protected void initController() throws Exception {
		
	}


	@Override
	protected void preSave(HttpServletRequest request, Object entity,
			BindException errors) {
		
	}
}
